#ifndef STORAGE_TUPLE_TUPLE_H
#define STORAGE_TUPLE_TUPLE_H 1

#include <common/macro/build.h>
#include <storage/itempointer.h>
#include <transaction/types.h>

typedef uint16_t tuple_offset_t;
typedef uint16_t tuple_atoms_count_t;
typedef uint16_t tuple_atom_size_t;

typedef enum tuple_delete_type_e {
	TUPLE_EXISTING,
	TUPLE_DELETE,
	TUPLE_UPDATE,
} tuple_delete_type_e;

typedef enum tuple_atom_type_e {
	TUPLE_ATOM_DATA,
	TUPLE_ATOM_BLOBLINK,
} tuple_atom_type_e;

typedef struct tuple_atom_t {
	tuple_atom_type_e type;

	int piggyback;
	char *data;
	tuple_atom_size_t size;
} tuple_atom_t;

typedef struct tuple_t {
	tuple_offset_t offset;
	
	transaction_id_t id_origin, id_insert, id_delete;
	tuple_delete_type_e deleted;
	command_id_t id_command;

	tuple_atom_t *atoms;
	tuple_atoms_count_t atoms_c;
} tuple_t;

API_LIBLOCAL tuple_t *tuple_new();
API_LIBLOCAL void tuple_init(tuple_t *);
API_LIBLOCAL enum tuple_atom_type_e tuple_atom_char_to_type(const char);
API_LIBLOCAL char tuple_atom_type_to_char(const tuple_atom_type_e);
API_LIBLOCAL inline size_t tuple_headersize(tuple_t *);
API_LIBLOCAL inline size_t tuple_datasize(tuple_t *);
API_LIBLOCAL int tuple_serialize(tuple_t *, char *, ssize_t);
API_LIBLOCAL int tuple_deserialize(tuple_t **, char *, ssize_t);
API_LIBLOCAL void tuple_deinit(tuple_t *);
API_LIBLOCAL void tuple_destroy(tuple_t *);

#endif
